//
//  AuthorizationManager.swift
//  AudioToolProject
//
//  Created by 邹琳 on 2019/5/13.
//  Copyright © 2019 邹琳. All rights reserved.
//

import UIKit
import AVFoundation
import Photos

class AuthorizationManager: NSObject {
	
    static func author_camera_photo_request(){
        if AVCaptureDevice.authorizationStatus(for: .video) == .notDetermined{
            AVCaptureDevice.requestAccess(for: .video) { (status) in
                if status{
                    print("允许访问相机")
                }else{
                    print("拒绝访问相机")
                }
            }
        }
        
        if PHPhotoLibrary.authorizationStatus() == .notDetermined{
            PHPhotoLibrary.requestAuthorization { (status) in
                let result = (status == .authorized)
                if result{
                    print("允许访问相册")
                }else{
                    print("拒绝访问相册")
                }
            }
        }
    }
    
    static func author_can_photo()->Bool{
        let status = PHPhotoLibrary.authorizationStatus()
        
        /** 第一次授权，系统会自动进行授权，这边就直接返回true */
        if status == .notDetermined{
            return true
        }else{
        	return PHPhotoLibrary.authorizationStatus() == .authorized
        }
    }
    
    static func author_can_camera()->Bool{
        let status = AVCaptureDevice.authorizationStatus(for: .video)
        
        /** 第一次授权，系统会自动进行授权，这边就直接返回true */
        if status == .notDetermined{
            return true
        }else{
        	return AVCaptureDevice.authorizationStatus(for: .video) == .authorized
        }
    }
    
}
